<?php 
	include '../init.php';

	$bz = $_GET['bz'];



	switch ($bz) {
		case 'edit':
		$per_list = $_POST;
		// var_dump($per_list);exit;

		// var_dump($bz);exit;
			$filed = '';

			foreach($per_list as $k => $v){
				//表单不能为空	
				if(!empty($v)){
				// 拼接sql语句 
					$field .= '`'.$k.'` = "'.htmlentities($v).'",';
				}
			}

			// var_dump(key($_FILES));
			if($_FILES[key($_FILES)]['error'] ){
				$field = rtrim($field,',');
			}else{

			}	//上传了图片,返回一个新的文件名
				$filename = up_img(key($_FILES), ROOT.'uploads/');
				$field .='`icon` ="'.$filename.'" ';
				
				$sql = 'select `icon` from user where id='.$_SESSION['home']['id'] ;
				
				$icon = query($sql)[0];
				// var_dump($icon['icon']);exit;
				delFile($icon['icon']);

			

			// echo $sql;exit;


			$sql = 'update user set '.$field.' where id='.$_SESSION['home']['id'];

			// echo $sql;exit;

			// var_dump($sql);exit;
			$_SESSION['home']['nickname'] = $per_list['nickname'];
			// var_dump($_SESSION['home']['nickname']);exit;

			if(zsg($sql)){
				notice('编辑成功, 正在前往个人资料页面...','personal.php');
			}else{
				notice('编辑失败,请重新来过');
			}

			break;	 

			case 'orderinfo':
			if(empty($_SESSION['home'])){
				notice('您尚未登录,请先登录,,','../login/login.php');
			}

			header('location:address.php');


			break;
		case 'editpwd':
		$alt_list =$_POST;
		// var_dump($alt_list); exit;

				if(empty($alt_list['pwd'])){
				notice('密码不能为空');		
				}
				// var_dump($alt_list['pwd']);exit;
				if($alt_list['pwd']){
					$v=md5($alt_list['pwd']);
				}

				if($v != $alt_list['old_pwd']){
					notice('原密码不正确...');
				}

			// $pid = ($_SESSION['home']['id']);

			// $sql = 'select `pwd` from user where pwd=' .$pid;
			// var_dump($sql);exit;
				// if($alt_list['pwd'] =! $alt_list['pwd'] {
				// 	notice('与原密码不一致');
				// }

				if( $alt_list['new_pwd'] !=$alt_list['new_repwd']){
					notice('两次修改的密码不一致');
					}

				if( $alt_list['pwd'] == $alt_list['new_pwd']){
					notice('旧密码与新密码一致，请重新输入');
					}



				$sql = 'update user set `pwd`="'.md5($alt_list['new_pwd']).'" where id='.$_SESSION['home']['id'];

				// var_dump($sql);exit;
				
				if(zsg($sql)){
					notice('修改成功, 正在前往个人资料...',URL.'home/login/login.php');
				}else{
					notice('修改失败,请重新来过');
				}


			break;
			case 'isPay':
				$id = $_GET['id'];
				// var_dump($id);exit;	

				$isPay = $_GET['isPay']==1?2:1;	
				$sql = 'update orders set `isPay` ='.$isPay.' where id='.$id;
				// var_dump($sql);exit;
					if(zsg($sql)){
					header('location:'.$_SERVER['HTTP_REFERER']);
					}else{
						notice('状态更新失败');
					}

			break;


			case 'orderWay':
				$id = $_GET['id'];

				$orderWay = $_GET['orderWay']==1?2:1;	
				$sql = 'update orders set `orderWay` ='.$orderWay.' where id='.$id;
					if(zsg($sql)){
						header('location:'.$_SERVER['HTTP_REFERER']);
					}else{
						notice('状态更新失败');
					}

			break;
		default:
			# code...
			break;
	}






 ?>